<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<input type="text" name="" id="" value="" />
		
		<button>点我跳转</button>
		
		<button>点我后退</button>
		
		<button>点我cookie</button>
		
		<progress width="100px" height="20px"></progress>
		
		<script type="text/javascript">
			
			var btn = document.getElementsByTagName("button");
			var Input = document.getElementsByTagName("input")[0];
			btn[0].onclick = function(){
				var inputValue = Input.value;
				location.href = "系统对象.html?keyword=" + inputValue;
				
			}
			
			btn[1].onclick = function(){
				//
//				history.go(-1);
				var inputValue = Input.value;
				//长久保存
				localStorage.setItem("keyword",inputValue);
				
				var arr = {
					arr:[1,22,3,4,5,6]
				};
				arr = JSON.stringify(arr);
				localStorage.setItem("kkkk",arr);
				
//				var res = JSON.parse(localStorage.getItem("kkkk"));
			}
			
			
			btn[2].onclick = function(){
				//设置cookie生命周期
				var inputValue = Input.value;
				var d = new Date();
				d.setTime(d.getTime() + 60*1000);
				console.log(d.toGMTString())
				document.cookie = "username = " + inputValue + ";Expires=" + d.toGMTString();
				
				
			}
			
			var xhr = new XMLHttpRequest();
			
			var src = "http://xyabc.gitee.io/test-music1/lesson.mp3";
			
			xhr.open("get",src,true);
			
			xhr.responseType = 'arraybuffer';
			
			xhr.send();
			xhr.addEventListener("readystatechange",function(e){
				var res = e.target;
				if(res.readyState == 4){
					if(res.state == 200){
						console.log(1111);
					}
				}
			})
			
			xhr.addEventListener("progress",function(e){
				console.log(e);
			})
			
			
			var pp = document.getElementsByTagName("progress")[0];
			
			//监听进度
			xhr.onprogress = function(e){
				if(e.lengthComputable){
//					var percentComputable = (e.loaded / e.total)*100 + "px";
					pp.setAttribute("value",e.loaded);
					pp.setAttribute("max",e.total);
				}
			}
			
			//实例化这个对象
			var audioContext = new (window.AudioContext || window.webkitAudioContext)();
			
			//监听完成下载
			xhr.onload = function(e){
				//得到二进制类型文件后进行解码
				var data = xhr.response;
//				console.log(data);
				
				audioContext.decodeAudioData(data,function(buffer){
					//创建内存音频资源
					var source = audioContext.createBufferSource();
					source.buffer = buffer;
					//链接
					source.connect(audioContext.destination);
					//循环
					source.loop = true;
					//播放
					source.start();
					
				},function(err){
					console.log(err);
				})
			}
			
		</script>
		
	</body>
</html>
